package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.activity.daydaycoupon.DdcListActivity;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.TourBean;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by david on 14-4-22.
 * 凑队去 - 微记
 */
public class TourSmallNoteAdapter extends ImageLoaderBaseAdapter {
    private LayoutInflater layoutInflater;
    private List<?> list = new ArrayList<TourBean>();
    private Context context;

    public TourSmallNoteAdapter(Context context, List<?> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        ImageView collectImageView;//收藏
        TextView titleTextview;
        TextView addPeopleNameTextView;//人名
        TextView addDataTextview; //时间


        TourBean bean = (TourBean) list.get(position);
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.tour_small_note_item, null);
        }
        imageView = (ImageView) convertView.findViewById(R.id.tour_small_note_item_ImageView);
        titleTextview = (TextView) convertView.findViewById(R.id.tour_small_note_nameTextView);
        addPeopleNameTextView = (TextView) convertView.findViewById(R.id.tour_small_note_item_add_people);
        addDataTextview = (TextView) convertView.findViewById(R.id.tour_small_note_item_add_data);
        collectImageView = (ImageView) convertView.findViewById(R.id.tour_small_note_item_collectButton);


        collectImageView.setVisibility(View.INVISIBLE);

        try {
            imageLoader.displayImage(bean.getThumb(), imageView, options, null);
            // 设置图片大小
            super.ajastImageViewSize(imageView, bean.getThumb(), ((DdcListActivity) context).getListView(), context);

            titleTextview.setText(bean.getTitle());
            addPeopleNameTextView.setText(bean.getUsername());
            //设置日期
            addDataTextview.setText(bean.getAdddate().replaceAll("\\-", "\\."));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }
}
